<?php

declare(strict_types=1);

namespace App\Model\Stat;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

/**
 *  每日统计
 */
class StatDaily extends Model
{
    protected $connection = 'stat';
    protected $table = 'stat_daily';

    static function checkTotalReg($start = '', $end = '', $channel = '')
    {
        $where = [];
        if ($start) $where[] = ['created_at', '>=', $start];
        if ($end) $where[] = ['created_at', '<', $end];
        if ($channel) $where[] = ['channel', $channel];
        $selectStr = 'SUM(reg_total) as reg, SUM(recharge_rmb) as rmb, SUM(new_recharge_coin) as new_coin';
        return self::where($where)->select(DB::raw($selectStr))->first();
    }
}
